/*
 * @Description: 规范性检测操作组件
 * @Author: Rfan
 * @Date: 2022-11-19 16:31:39
 * @LastEditTime: 2022-12-08 14:33:41
 */

import { useMemo, useState } from 'react';
import { Button, Space } from 'antd';
import cs from 'classnames';
import { useBaseInfoContext } from '../contexts/BaseInfoContext';
import AddBaseInfoDialog from './dialogs/AddBaseInfoDialog';

const PageOperate = (props: any) => {
  const { classname } = props;
  const { selectItems, deleteItem } = useBaseInfoContext();

  const [visible, setVisible] = useState(false);

  const deleteRegistrationItem = () => {
    deleteItem(selectItems, `您已选择了${selectItems.length}个档案，是否确认移除?`);
  };

  return (
    <>
      <div className={cs('filter-container', 'page-operate', classname)}>
        <div>档案基本信息及案卷外观调查登记表</div>
        <Space size="small">
          <Button
            onClick={() => {
              setVisible(true);
            }}
          >
            新建
          </Button>
          <Button
            disabled={selectItems.length <= 0}
            onClick={() => {
              deleteRegistrationItem();
            }}
          >
            删除
          </Button>
        </Space>
      </div>

      {useMemo(
        () => (
          <AddBaseInfoDialog
            visible={visible}
            onClose={() => {
              setVisible(false);
            }}
          />
        ),
        [visible]
      )}
    </>
  );
};

export default PageOperate;
